package com.jiepu.daily.corejava.advanceed.part8xml.dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

/**
 * @Description:
 * @author: xinjie
 * @date: 2020/8/17  9:01
 */
public class Dom4jDemo {
	public static void main(String[] args) throws DocumentException {
		// 1、 调用Dom4j解析器对象，读取xml文件
		SAXReader reader = new SAXReader();

		// 2、 调用read()读取xml文件，解析成一个文档对象。
		String path = "src/com/jiepu/daily/advanceed/part8xml/classroom.xml";
		Document doc = reader.read(path);

		// 3、解析的第一步
		Element root = doc.getRootElement();
		// 4、获取 name
		Element nameElm = root.element("name");
		System.out.println(nameElm.getName() + ":" + nameElm.getText());


		// 5、获取 teacher
		Element teacherEle = root.element("teacher");
		List<Element> childofTeacher = teacherEle.elements();
		for (Element child : childofTeacher) {
			System.out.println(child.getName() + ":" + child.getText());
		}

		// 6、 groups
		Element groups = root.element("groups");
		List<Element> child = groups.elements();



	}
}
